<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()+ path + "/";
%>
<html>
	 <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
        <meta name="format-detection" content="telephone=no">
        <meta charset="UTF-8">
        <meta name="description" content="Violate Responsive Admin Template">
        <meta name="keywords" content="Super Admin, Admin, Template, Bootstrap">
        <link href="<%=path %>/assets2/js/bootstrap-table.css" rel="stylesheet">
        <script src="<%=path %>/assets2/js/jquery-1.11.1.min.js"></script>
        <script src="<%=path %>/assets2/js/bootstrap-table.js"></script>
   		<script src="<%=path %>/assets2/js/locale/bootstrap-table-zh-CN.js"></script>
   		<script src="<%=path %>/assets2/js/bootstrap.min.js"></script>
   		<script src="<%=path%>/assets2/js/bootstrap-datetimepicker.min.js"></script>
		<link rel="stylesheet" href="<%=path%>/assets2/js/bootstrap-datetimepicker.min.css">
		<script src="<%=path %>/assets2/js/jquery.timers-1.1.2.js"></script>
		
    </head>
    <body>
<div class="row">
	<ol class="breadcrumb">
		<li><a href="<%=path%>/index"><span
				class="glyphicon glyphicon-home"></span></a></li>
		<li class="active">每日扫码付钱</li>
	</ol>
</div>

<input type="hidden" id="settlementId">
<input type="hidden" id="merchantPrice">
<input type="hidden" id="openId">

<div class="panel panel-default">
	<div class="panel-body">
	
		<div style="background-color: #E6E6FA;">
			<div class="layui-card"><br>
			  <div class="layui-card-body">
			  	<div class="row">
			  		<div class="col-md-3 col-md-offset-2" style="font-size: 18px;">可用余额:<span id="moneyNum">0</span></div>
			  		<div class="col-md-7">
			  			<div class="row">
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="请输入提现的金额">
							</div>			  			
							<div class="col-md-4">
								<input type="text" class="form-control" placeholder="请输入提现的备注">
							</div>			  			
							<div class="col-md-4">
								<button type="button" class="btn btn-primary" onclick="withdrawalBtn()">提现</button>
							</div>			  			
			  			</div>
			  		</div>
			  	</div>
			  	<br>
			  </div>
			</div>
		</div>
		
	</div>
</div>
   <script type="text/javascript">
   $(function () {
	    getMoneyInfo();
	    
	});


	//获取提现的金额
	function getMoneyInfo(){
		$.ajax({
			 type:"POST",
	         url: "<%=path %>/supplier/getOrderSettlementsInfo",
	         success: function(data,status,xhr){
	        	 if(data.orderSettlements==null||data.orderSettlements==''){
	        		 $("#merchantPrice").val(null);
		        	 $("#settlementId").val(null);
		        	 $("#openId").val(null);
		        	 $('body').everyTime('3s',queryOrder);
	        	 }else{
	        		 $('body').everyTime('3s',queryOrder);
	        		 $("#merchantPrice").val(data.orderSettlements.merchantPrice);
	        		 $("#moneyNum").text(data.orderSettlements.merchantPrice);
		        	 $("#settlementId").val(data.orderSettlements.settlementId);
	        	 }
	         }
		})
	}
	
	//提现按钮
	function withdrawalBtn(){
		var openId =$("#openId").val();
		if(openId==null||openId==""){
			$.ajax({
		    	url: "<%=path %>/common/createWxQRPay",
		        timeout: 300000,
		        dataType: "json",
		        type: "get",
		        success : function(data) {
		        	var ewmurl ="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data="+data;
		        	//页面层
		        	var ewHtml = '<img alt="" src="'+ewmurl+'">';
		        	layer.open({
		        	  type: 1,
		        	  title:"购买服务",
		        	  skin: 'layui-layer-rim', //加上边框
		        	  area: ['180px', '220px'], //宽高
		        	  content: ewHtml
		        	});
		        },error : function() {
		        }
		    })
		}else{
			
		}
	}
	//查询是否扫码成功
	function queryOrder(){
		$.ajax({
	    	url: "<%=path %>/common/queryWebWXPayState1",
	        timeout: 300000,
	        dataType: "json",
	        type: "get",
	        success : function(data) {
	        	if(data.mapWXResult!=null&&data.mapWXResult!=''){
	        		if(data.mapWXResult.trade_state=='SUCCESS'){
		        		$('body').stopTime(); 
		        		layer.closeAll();
		        		swal({ 
							  title: "操作成功", 
							  text: "购买提现服务成功", 
							  type: "success",
						});
		        	}else if(data.mapWXResult.trade_state=='NOTPAY'){
		        	}else if(data.mapWXResult.trade_state=='CLOSED'){
		        	}else if(data.mapWXResult.trade_state=='REVOKED'){
		        	}else if(data.mapWXResult.trade_state=='PAYERROR'){
		        	}
	        	}
	        },error : function() {
	        	layer.closeAll();
        		swal({ 
					  title: "操作失败", 
					  text: "网络错误", 
					  type: "error",
				});
	        }
	    })
	};
   </script>
   </body>
</html>